home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 March / Pc Users extra 6.iso / pshare95 / prog / formula1 / vcform1.z / ReportWriter.bas < prev    next >
Encoding:
BASIC Source File  |  1997-09-11  |  10.4 KB  |  334 lines

  1. Attribute VB_Name = "Module1"
  2. Global wrkJet As Workspace
  3. Global dbs As Database
  4. Global SQL As SQLInfo
  5. Global ReportType As String
  6.  
  7. Public Sub GetTables(cbo As ComboBox)
  8.  
  9.     Dim NumTables As Integer
  10.     
  11.     ' Fill in combo with table names.
  12.     For NumTables = 0 To wrkJet.Databases(0).TableDefs.Count - 1
  13.         cbo.AddItem wrkJet.Databases(0).TableDefs(NumTables).Name
  14.     Next NumTables
  15.  
  16. End Sub
  17.  
  18. Public Sub GetColumns(lst As ListBox, TableName As String)
  19.     
  20.     Dim NumColumns As Integer
  21.  
  22.     ' Fill in listbox with column names.
  23.     For NumColumns = 0 To wrkJet.Databases(0).TableDefs(TableName).Fields.Count - 1
  24.         lst.AddItem wrkJet.Databases(0).TableDefs(TableName).Fields(NumColumns).Name
  25.     Next NumColumns
  26.     
  27. End Sub
  28.  
  29. Public Sub PopulateSheet()
  30.     Dim pConnect As String
  31.     Dim pQuery As String
  32.     Dim SQLFields As String
  33.     Dim GroupFields As String
  34.     Dim pRetCode As Integer
  35.     Dim x As Integer
  36.     Dim NumColumns As Integer
  37.     
  38.     pConnect = "DSN=Southcreek;DBQ=F:\VCI\VcDbC\database\Southcrk.mdb;DefaultDir=F:\VCI\VcDbC\database\;DriverId=25;FIL=MS Access;MaxBufferSize=512;PageTimeout=5;UID=admin;"
  39.     
  40.     If SQL.Fields.Count = 0 Then
  41.         For NumColumns = 0 To wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields.Count - 1
  42.             SQL.Fields.Add wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields(NumColumns).Name, wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields(NumColumns).Name
  43.         Next NumColumns
  44.     End If
  45.     
  46.     For x = 1 To SQL.Fields.Count
  47.         SQLFields = SQLFields & SQL.Fields.Item(x).Name & ", "
  48.     Next x
  49.     
  50.     For x = 1 To SQL.Groups.Count
  51.         GroupFields = GroupFields & SQL.Groups.Item(x).Name & ", "
  52.     Next x
  53.     
  54.     SQLFields = Left(SQLFields, Len(SQLFields) - 2)
  55.     If SQL.Groups.Count > 0 Then
  56.         GroupFields = " Group By " & SQLFields & " Order By " & Left(GroupFields, Len(GroupFields) - 2)
  57.     End If
  58.     pQuery = "Select " & SQLFields & " From " & SelectFields.cboTables.Text & GroupFields
  59.     
  60.     ReportWriter.F1Book1.ODBCConnect pConnect, True, pRetCode
  61.     ReportWriter.F1Book1.ODBCQuery pQuery, 1, 1, False, True, True, True, False, pRetCode
  62.     ReportWriter.F1Book1.ODBCDisconnect
  63.     
  64.     Select Case ReportType
  65.         Case "Report Wizard"
  66.             Call ReportWizardFormat
  67.         Case "AutoReport:  Tabular"
  68.             Call FormatTabular
  69.     End Select
  70.     Debug.Print pConnect
  71. End Sub
  72.  
  73. Public Sub FormatTabular()
  74.     Dim x As Integer
  75.     Dim NumColumns As Integer
  76.     
  77.     NumColumns = wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields.Count
  78.     With ReportWriter.F1Book1
  79.         .ShowRowHeading = False
  80.         .ShowColHeading = False
  81.         .ShowGridLines = False
  82.         .PrintGridLines = False
  83.         
  84.         .SetSelection -1, -1, -1, -1
  85.         .FontSize = 8
  86.         
  87.         .InsertRange 1, 1, 2, 256, F1ShiftRows
  88.         .TextRC(1, 1) = SelectFields.cboTables.Text
  89.         .SetSelection 1, 1, 1, 1
  90.         .FontBold = True
  91.         .FontItalic = True
  92.         .FontSize = 18
  93.         .FontColor = RGB(0, 0, 128)
  94.         
  95.         For x = 0 To NumColumns - 1
  96.             .TextRC(2, x + 1) = wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields(x).Name
  97.             .SetSelection 2, x + 1, 2, x + 1
  98.             .FontBold = True
  99.             .FontItalic = True
  100.             .FontSize = 10
  101.             .FontColor = RGB(0, 0, 128)
  102.         Next x
  103.         
  104.         .SetSelection 2, 1, 2, NumColumns
  105.         .SetBorder -1, -1, -1, -1, 5, 0, 0, 0, 0, 0, RGB(0, 0, 128)
  106.         
  107.         .SetRowHeightAuto -1, -1, -1, -1, False
  108.         
  109.         .ShowSelections = F1Off
  110.         .ShowTabs = F1TabsOff
  111.         
  112.         .FixedRows = 2
  113.         .PrintTitles = "$A$1:$IV$2"
  114.         
  115.      End With
  116. End Sub
  117.  
  118.  
  119. Public Sub PopulateColumnar()
  120.     Dim RecordCount As Long
  121.     Dim ColumnCoun As Long
  122.     Dim RecSet As Recordset
  123.     Dim nRow As Long
  124.     Dim x As Integer
  125.     Dim y As Integer
  126.     
  127.     nRow = 0
  128.     
  129.     With ReportWriter.F1Book1
  130.         .ShowRowHeading = False
  131.         .ShowColHeading = False
  132.         .ShowGridLines = False
  133.         .ShowSelections = F1Off
  134.         .PrintGridLines = False
  135.     
  136.         .SetSelection -1, -1, -1, -1
  137.         .FontSize = 8
  138.         
  139.         .SetSelection -1, 1, -1, 1
  140.         .FontBold = True
  141.         .FontItalic = True
  142.         .FontSize = 10
  143.         .FontColor = RGB(0, 0, 128)
  144.         
  145.         .TextRC(1, 1) = SelectFields.cboTables.Text
  146.         .SetSelection 1, 1, 1, 1
  147.         .FontBold = True
  148.         .FontItalic = True
  149.         .FontSize = 18
  150.         .FontColor = RGB(0, 0, 128)
  151.                 
  152. '        .SetSelection -1, 3, -1, 3
  153. '        .SetBorder -1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0
  154.         .SetSelection 1, 3, 1, 3
  155.         .SetBorder 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0
  156.         .SetSelection 1, 1, 1, 3
  157.         .SetBorder -1, -1, -1, -1, 5, 0, 0, 0, 0, 0, RGB(0, 0, 128)
  158.         
  159.         .FixedRows = 1
  160.         .PrintTitles = "$A$1:$IV$1"
  161.         
  162.     End With
  163.     
  164.     Set RecSet = dbs.OpenRecordset("Select * From " & SelectFields.cboTables.Text)
  165.     
  166.     RecSet.MoveLast
  167.     RecSet.MoveFirst
  168.     
  169.     nRow = 1
  170.     
  171.     RecordCount = RecSet.RecordCount
  172.     ColumnCount = wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields.Count
  173.     
  174.     For x = 1 To RecordCount
  175.         For y = 0 To ColumnCount - 1
  176.             nRow = nRow + 1
  177.             If nRow >= ReportWriter.F1Book1.MaxRow Then
  178.                 Exit For
  179.             End If
  180.             ReportWriter.F1Book1.TextRC(nRow, 1) = RecSet.Fields(y).Name
  181.             If Not IsNull(RecSet.Fields(RecSet.Fields(y).Name).Value) Then
  182.                 ReportWriter.F1Book1.TextRC(nRow, 3) = RTrim(RecSet.Fields(RecSet.Fields(y).Name).Value)
  183.             End If
  184.         Next y
  185.         If nRow < ReportWriter.F1Book1.MaxRow Then
  186.             nRow = nRow + 1
  187.             ReportWriter.F1Book1.AddRowPageBreak nRow
  188.         End If
  189.         RecSet.MoveNext
  190.     Next x
  191.     
  192.     ReportWriter.F1Book1.SetColWidthAuto -1, -1, -1, -1, False
  193.     ReportWriter.F1Book1.SetRowHeightAuto -1, -1, -1, -1, False
  194. End Sub
  195.  
  196. Public Sub ReportWizardFormat()
  197.     Dim x As Integer
  198.     
  199.     With ReportWriter.F1Book1
  200.         .ShowRowHeading = False
  201.         .ShowColHeading = False
  202.         .ShowGridLines = False
  203.         .ShowTabs = F1TabsOff
  204.         .PrintGridLines = False
  205.         
  206.         .SetSelection -1, -1, -1, -1
  207.         .FontSize = 8
  208.         
  209.         For x = 1 To SQL.Groups.Count
  210.             .SetSelection -1, x, -1, x
  211.             .FontBold = True
  212.             .FontSize = 10
  213.             .FontColor = RGB(0, 0, 128)
  214.         Next x
  215.         
  216.         .SetSelection 1, 1, 1, 1
  217.         .FontBold = True
  218.         .FontItalic = True
  219.         .FontSize = 18
  220.         .FontColor = RGB(0, 0, 128)
  221.         
  222.         .SetSelection 2, -1, 2, -1
  223.         .FontBold = True
  224.         .FontItalic = True
  225.         .FontSize = 10
  226.         .FontColor = RGB(0, 0, 128)
  227.         .SetBorder -1, -1, -1, -1, 5, 0, 0, 0, 0, 0, RGB(0, 0, 128)
  228.         
  229.         .SetColWidthAuto -1, -1, -1, -1, False
  230.         .SetRowHeightAuto -1, -1, -1, -1, False
  231.  
  232.         .FixedRows = 2
  233.         .PrintTitles = "$A$1:$IV$2"
  234.         
  235.     End With
  236.     
  237. End Sub
  238.  
  239. Public Sub PopulateReportWizard()
  240.     Dim RecordCount As Long
  241.     Dim ColumnCoun As Long
  242.     Dim RecSet As Recordset
  243.     Dim nRow As Long
  244.     Dim nCol As Long
  245.     Dim x As Integer
  246.     Dim y As Integer
  247.     Dim z As Integer
  248.     Dim pQuery As String
  249.     Dim isgroup As Boolean
  250.     
  251.     ReportWriter.F1Book1.TextRC(1, 1) = SelectFields.cboTables.Text
  252.     
  253.     For x = 1 To SQL.Groups.Count
  254.         SQLFields = SQLFields & SQL.Groups.Item(x).Name & ", "
  255.     Next x
  256.     
  257.     For x = 1 To SQL.Fields.Count
  258.         If InStr(SQLFields, SQL.Fields(x).Name) = 0 Then
  259.             SQLFields = SQLFields & SQL.Fields.Item(x).Name & ", "
  260.         End If
  261.     Next x
  262.     
  263.     For x = 1 To SQL.Groups.Count
  264.         GroupFields = GroupFields & SQL.Groups.Item(x).Name & ", "
  265.     Next x
  266.     
  267.     SQLFields = Left(SQLFields, Len(SQLFields) - 2)
  268.     If SQL.Groups.Count > 0 Then
  269.         GroupFields = " Group By " & SQLFields & " Order By " & Left(GroupFields, Len(GroupFields) - 2)
  270.     End If
  271.     pQuery = "Select " & SQLFields & " From " & SelectFields.cboTables.Text & GroupFields
  272.     
  273.     ReDim GroupArray(1, SQL.Groups.Count) As String
  274.     
  275.     For x = 1 To SQL.Groups.Count
  276.         GroupArray(1, x) = SQL.Groups(x).Name
  277.     Next x
  278.     
  279.     Set RecSet = dbs.OpenRecordset(pQuery)
  280.     
  281.     RecSet.MoveLast
  282.     RecSet.MoveFirst
  283.     
  284.     nRow = 1
  285.     nCol = 1
  286.     RecordCount = RecSet.RecordCount
  287.     ColumnCount = RecSet.Fields.Count
  288.     
  289.     For x = 1 To RecordCount
  290.         nRow = nRow + 1
  291.         
  292.         If x = 1 Then
  293.             For y = 0 To ColumnCount - 1
  294.                 ReportWriter.F1Book1.TextRC(nRow, nCol) = RecSet.Fields(y).Name
  295.                 If y = ColumnCount - 1 Then
  296.                     nRow = nRow + 1
  297.                 End If
  298.                 nCol = nCol + 1
  299.             Next y
  300.         End If
  301.         For y = 0 To ColumnCount - 1
  302.             If nRow >= ReportWriter.F1Book1.MaxRow Then
  303.                 Exit For
  304.             End If
  305.             For z = 1 To SQL.Groups.Count
  306.                 If RecSet.Fields(y).Name = SQL.Groups(z).Name Then
  307.                     If GroupArray(1, z) <> RecSet.Fields(RecSet.Fields(y).Name).Value Then
  308.                         If Not IsNull(RecSet.Fields(RecSet.Fields(y).Name).Value) Then
  309.                             ReportWriter.F1Book1.TextRC(nRow, nCol) = RTrim(RecSet.Fields(RecSet.Fields(y).Name).Value)
  310.                         End If
  311.                     End If
  312.                     If Not IsNull(RecSet.Fields(RecSet.Fields(y).Name).Value) Then
  313.                         GroupArray(1, z) = RecSet.Fields(RecSet.Fields(y).Name).Value
  314.                     End If
  315.                     nCol = nCol + 1
  316.                 End If
  317.             Next z
  318.             If Not IsNull(RecSet.Fields(RecSet.Fields(y).Name).Value) Then
  319.                 ReportWriter.F1Book1.TextRC(nRow, nCol) = RTrim(RecSet.Fields(RecSet.Fields(y).Name).Value)
  320.             End If
  321.             nCol = nCol + 1
  322.         Next y
  323.         RecSet.MoveNext
  324.         nCol = 1
  325.     Next x
  326.     
  327.     For x = 1 To SQL.Groups.Count
  328.         ReportWriter.F1Book1.DeleteRange 3, x + 1, 16383, x + 1, F1ShiftHorizontal
  329.     Next x
  330.         
  331.     Call ReportWizardFormat
  332.  
  333. End Sub
  334.